#include "kdcchapter.h"

#include <kdclib.h>
#include <KLocale>
#include <KIcon>

KDCChapter::KDCChapter( KDCMovie *aMovie ) : KDCObject( KDC::Chapter, aMovie )
{

}

KDCChapter::~KDCChapter()
{

}

int KDCChapter::count() const
{
	return pData.count();
}

void KDCChapter::clear()
{
	pData.clear();
}

const QPair<int,QPixmap>& KDCChapter::chapter( int aIndex ) const
{
	return pData.at( aIndex );
}

void KDCChapter::sort()
{
	//qSort( pData.begin(), pData.end() );
}

int KDCChapter::add( int aPos, const QPixmap &aPixmap )
{
	QList<QPair<int,QPixmap> >::const_iterator it;
	for ( it = pData.constBegin(); it != pData.constEnd(); ++it )
		if ( (*it).first == aPos )
			return - 1;
	pData.append( qMakePair( aPos, aPixmap ) );
	return count() - 1;
}

void KDCChapter::remove( int aIndex )
{
	if ( isInRange( aIndex, 0, pData.size() - 1 ) ) 
		pData.removeAt( aIndex );
}

KIcon KDCChapter::icon() const
{
	return KIcon("edit-find");
}

QString KDCChapter::title() const
{
	return i18n( "Chapters ( %1 )" ).arg( count() );
}
